﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class Storage_ChooseLocation : Form
    {

        AddProduct addproduct;

        protected AddProduct AddProduct
        {
            get { return addproduct; }
        }

        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        public Storage_ChooseLocation(AddProduct addproduct)
            : this()
        {
            this.addproduct = addproduct;
        }

        public Storage_ChooseLocation()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        protected void LoadData()
        {
            IQueryable<Storage_StorageLocations> dataQuery = (from sm in diveDatabase.Storage_StorageLocations
                                                                select sm);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            LocationList.DataSource = bindingSource;


            // Hide ID-Columns
            LocationList.Columns["ID"].Visible = false;
            LocationList.Columns["Bereich"].Visible = true;
            LocationList.Columns["Reihe"].Visible = true;
            LocationList.Columns["Etage"].Visible = true;
            LocationList.Columns["PlatzNr"].Visible = true;
            LocationList.Columns["Closed"].Visible = true;

            // Set Column Headers
            LocationList.Columns["PlatzNr"].HeaderText = "Fach";


        }

        private void Storage_ChooseLocation_Load(object sender, EventArgs e)
        {
            LoadData();

            label1.Visible = true;
            label1.DataBindings.Add(new Binding("Text", bindingSource, "ID"));
            label1.Visible = false;
        }

        private void btSubmit_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            AddProduct.Lagerfach = label1.Text;
            DialogResult = DialogResult.OK;
            label1.Visible = false;
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
